package com.qin.entity.subcomponents;

import com.qin.entity.ExecuteBean;
import com.qin.entity.ExecuteLog;
import com.qin.service.ExecuteService;
import com.qin.service.impl.ExecuteServiceImpl;

import java.util.HashMap;
import java.util.Map;

/*
 * 【子组件】列名变量提取
 */
public class ColumnExtractSubComponent {

    //所属组件ID
    private String component_id;
    //列名
    private String column_name;
    //赋值变量名
    private String column_assign_name;

    private ExecuteService executeService = new ExecuteServiceImpl();

    public ColumnExtractSubComponent(String component_id, String column_name, String column_assign_name) {
        this.component_id = component_id;
        this.column_name = column_name;
        this.column_assign_name = column_assign_name;
    }

    public void execute(ExecuteBean executeBean){

        //设置ExecuteLog对象的各属性
        ExecuteLog executeLog = new ExecuteLog(executeBean.getExecute_id(), executeBean.getFunction_id(),
                executeBean.getTestcase_id(), executeBean.getComponent_id(), executeBean.getSubcomponent_id(), "");

        //获取父组件查询结果的第一条
        Map<String, String> resultMap = executeBean.getDbQueryResultMap().get(component_id).get(0);
        //获取对列名下对应的查询结果
        String column_assign_value = resultMap.get(column_name.toUpperCase());

        //插入日志
        executeService.insertExecuteLog(executeLog, ">>>>>列名变量提取：提取列名=" + column_name.toUpperCase());
        executeService.insertExecuteLog(executeLog, ">>>>>列名变量提取：提取变量名=" + column_assign_name + "，提取变量值=" + column_assign_value);

        Map<String, String> retMap = new HashMap();
        retMap.put(column_assign_name, column_assign_value);
        //把map的值添加到executeBean中
        executeBean.getParaMap().putAll(retMap);
    }
}
